/************************************************************
 * Project Name         [Thinking_In_Java]
 * File Name            [EditMenu.java]
 * Creation Date        [11-Jul-2014]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ************************************************************/
package pkg_02_gui.notepad_V1.ui.edit;

import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;

import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.KeyStroke;

/**
 * 编辑菜单
 * 
 * @author 不落的太阳(Sean Yang)
 * @version 1.0
 * @since JDK 6
 * 
 */
public abstract class EditMenu extends JMenu {

	private static final long serialVersionUID = 9041875198671579371L;

	/** **********************编辑菜单*********************** */
	private JMenuItem undoItem; // 撤销菜单项
	private JMenuItem redoItem; // 恢复撤销菜单项
	private JMenuItem cutItem; // 剪切菜单项
	private JMenuItem copyItem; // 复制菜单项
	private JMenuItem pasteItem; // 粘贴菜单项
	private JMenuItem deleteItem; // 删除菜单项
	private JMenuItem findItem;// 查找菜单项
	private JMenuItem findNextItem; // 查找下一个菜单项
	private JMenuItem replaceItem; // 替换菜单项
	private JMenuItem turnToItem; // 转到菜单项
	private JMenuItem allSelectedItem; // 全选菜单项
	private JMenuItem dateTimeItem;// 日期时间菜单项

	/**
	 * 初始化编辑菜单
	 * 
	 * @param menuName
	 */
	private void initEditMenu() {
		// 编辑菜单
		this.setMnemonic(KeyEvent.VK_E); // 设置快捷键为Alt+E

		undoItem = new JMenuItem("撤销(Z)");// 撤销菜单项
		undoItem.setMnemonic('Z'); // 设置激活键为Z
		undoItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z,
				InputEvent.CTRL_MASK));// 设置快捷键为Ctrl+Z
		this.add(undoItem);

		redoItem = new JMenuItem("恢复撤销(B)"); // 恢复撤销菜单项
		redoItem.setMnemonic('B'); // 设置激活键为B
		redoItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_B,
				InputEvent.CTRL_MASK));// 设置快捷键为Ctrl+B
		this.add(redoItem);

		addSeparator(); // 添加文件分隔符

		cutItem = new JMenuItem("剪切(T)"); // 剪切菜单项
		cutItem.setMnemonic('T'); // 设置激活键为T
		cutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,
				InputEvent.CTRL_MASK));// 设置快捷键为Ctrl+X
		this.add(cutItem);

		copyItem = new JMenuItem("复制(C)"); // 复制菜单项
		copyItem.setMnemonic('C'); // 设置激活键为C
		copyItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,
				InputEvent.CTRL_MASK));// 设置快捷键为Ctrl+C
		this.add(copyItem);

		pasteItem = new JMenuItem("粘贴(P)"); // 粘贴菜单项
		pasteItem.setMnemonic('P'); // 设置激活键为P
		pasteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,
				InputEvent.CTRL_MASK));// 设置快捷键为Ctrl+C
		this.add(pasteItem);

		deleteItem = new JMenuItem("删除(L)"); // 删除菜单项
		deleteItem.setMnemonic('L'); // 设置激活键为L
		deleteItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE,
				InputEvent.CTRL_MASK));// 设置快捷键为Ctrl+Delete
		this.add(deleteItem);

		addSeparator(); // 添加文件分割符

		findItem = new JMenuItem("查找(F)"); // 查找菜单项
		findItem.setMnemonic('F'); // 设置激活键为F
		findItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F,
				InputEvent.CTRL_MASK));// 设置快捷键为Ctrl+F
		this.add(findItem);

		findNextItem = new JMenuItem("查找下一个(N)");// 查找下一个菜单项
		findNextItem.setMnemonic('N');// 设置激活键为N
		findNextItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3,
				InputEvent.CTRL_MASK));// 设置快捷键为Ctrl+F3
		this.add(findNextItem);

		replaceItem = new JMenuItem("替换(R)...");// 替换菜单项
		replaceItem.setMnemonic('R');// 设置激活键为R
		replaceItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H,
				InputEvent.CTRL_MASK));// 设置快捷键为Ctrl+H
		this.add(replaceItem);

		turnToItem = new JMenuItem("转到(G)...");// 转到菜单项
		turnToItem.setMnemonic('G');// 设置激活键为G
		turnToItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G,
				InputEvent.CTRL_MASK));// 设置快捷键为Ctrl+G
		turnToItem.setEnabled(false);
		this.add(turnToItem);

		addSeparator();

		allSelectedItem = new JMenuItem("全选(A)...");// 全选菜单项
		allSelectedItem.setMnemonic('A');// 设置激活键为A
		allSelectedItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A,
				InputEvent.CTRL_MASK));// 设置快捷键为Ctrl+A
		this.add(allSelectedItem);

		dateTimeItem = new JMenuItem("时间/日期(D)");// 日期时间菜单项
		dateTimeItem.setMnemonic('D');// 设置激活键为D
		dateTimeItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5,
				InputEvent.CTRL_MASK));// 设置快捷键为Ctrl+F5
		this.add(dateTimeItem);
	}

	public EditMenu(String menuName) {
		super(menuName);
		initEditMenu();
	}

	public EditMenu() {
		super();
	}

	public JMenuItem getUndoItem() {
		return undoItem;
	}

	public JMenuItem getRedoItem() {
		return redoItem;
	}

	public JMenuItem getCutItem() {
		return cutItem;
	}

	public JMenuItem getCopyItem() {
		return copyItem;
	}

	public JMenuItem getPasteItem() {
		return pasteItem;
	}

	public JMenuItem getDeleteItem() {
		return deleteItem;
	}

	public JMenuItem getFindItem() {
		return findItem;
	}

	public JMenuItem getFindNextItem() {
		return findNextItem;
	}

	public JMenuItem getReplaceItem() {
		return replaceItem;
	}

	public JMenuItem getTurnToItem() {
		return turnToItem;
	}

	public JMenuItem getAllSelectedItem() {
		return allSelectedItem;
	}

	public JMenuItem getDateTimeItem() {
		return dateTimeItem;
	}
}
